package org.corey.share.db.dao;

import java.util.List;

import javax.persistence.Query;

import org.corey.share.db.entity.User;

public class UserDaoImpl extends DefaultBaseDao implements UserDao {

	@SuppressWarnings("unchecked")
	public User getUserByName(String userName) {
		Query query = getEM().createQuery(
				"SELECT u FROM User u WHERE u.userName=:userName");
		query.setParameter("userName", userName);
		List<User> us = (List<User>) query.getResultList();
		if (us.size() > 0) {
			return us.get(0);
		}
		return null;
	}

	public boolean updateUser(User user) {
		return this.update(user);
	}

	public boolean addUser(User user) {
		return this.save(user);
	}
}
